<?
session_start();
include("../../../include/class.mysqldb.php");
include("../../../include/config.inc.php");

$scroll = $_REQUEST['scrollx'];
$member_id = $_SESSION['id'];
$success = false;
$today = date ("Y-m-d H:i:s");
	
if ($member_id<>''){
	
	$strSQL = "SELECT * FROM attribute WHERE att_name = '".$member_id."' AND att_value = 'play_game1'";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	$objResult = @mysql_fetch_row($objQuery);
	
	
	//echo $strSQL."<br>".$objResult;
	
	if ($objResult==''){
		//echo "no<br>"; 
		
		$InsertCrossword = "INSERT INTO attribute ";
		$InsertCrossword .="(att_name,att_value,op,value) ";
		$InsertCrossword .="VALUES ";
		$InsertCrossword .="('".$member_id."',";
		$InsertCrossword .="'play_game1',";
		$InsertCrossword .="'==',";
		$InsertCrossword .="'1'),";
		$objInsertCrossword = mysql_query($InsertCrossword);
		
		$sql_scroll = "INSERT INTO tb_quiz VALUES('','".$member_id."','8',".$scroll.",'".$today."')";
		$obj2 = mysql_query($sql_scroll); 
		
		$success = true;
		
	
			
	} else {
		//echo "yes<br>"; 
		//echo $objResult['value']."<br>";
	
		$objResult = @mysql_fetch_object($objQuery);
		//echo "value = ".$objResult->value."<br>";
		if ($objResult->value <> 2 ){
			
			$UpdateCrossword = "UPDATE attribute SET ";
			$UpdateCrossword .="value = '2' ";
			$UpdateCrossword .="WHERE ";
			$UpdateCrossword .="att_name = '".$member_id."' ";
			$UpdateCrossword .="AND att_value = 'play_game1' ";
						
			//echo $UpdateCrossword."<br>";
			$objUpdateCrossword = mysql_query($UpdateCrossword) or die ("Error Query [".$UpdateCrossword."]");
			
			
			$ScrollOld = "SELECT * FROM tb_quiz WHERE member_id = '".$member_id."' AND quiz_q=8";
			$objScrollOld = mysql_query($ScrollOld);
			$objResultScrollOld = mysql_fetch_array($objScrollOld);

			
			if ($objResultScrollOld['quiz_scroll'] < $scroll){
				$UpdateScroll = "UPDATE tb_quiz SET quiz_scroll = ".$scroll.", datetime = '".$today."' WHERE id='".$member_id."' AND quiz_q=8";
						
				//echo $UpdateScroll."<br>";
				$objUpdateScroll = mysql_query($UpdateScroll);
			}
	
			$success = true;
	
		} else {
			$success = false;
			//echo "You can not save scroll";
		}
	
	} 


}



	if($success)
	{
		?>
        <center>
        	Save scroll complete.
        </center>
		<?
	}
	else
	{
		?>
        <center>
        	You can not save scroll.
        </center>
		<?
	 	
	}
	
?>
<center><a href="javascript: window.close()">close window</a></center>